﻿<!DOCTYPE html>
<html class="theme theme-white">
<head>
<meta charset="utf-8">
<title><center> Api 工具类的使用说明 </center></title>
<link href="https://www.zybuluo.com/static/assets/template-theme-white.css" rel="stylesheet" media="screen">
<style type="text/css">

#wmd-preview h1  {
    color: #0077bb; /* 将标题改为蓝色 */
}</style>
</head>
<body class="theme theme-white">
<div id="wmd-preview" class="wmd-preview wmd-preview-full-reader"><div class="md-section-divider"></div><div class="md-section-divider"></div><h1 data-anchor-id="0fz0" id="api-工具类的使用说明"><center> Api 工具类的使用说明 </center></h1><blockquote data-anchor-id="llci" class="white-blockquote">
  <p>本文是针对Face++ 官网Api的封装和调用示例。使用Okhttp封装。最终是一个jar 包。适用于所有能用jar包的项目。 <br>
  调用示例是andorid项目。有兴趣的可以Github看下。</p>
</blockquote><p data-anchor-id="rmyg"><br></p><div class="md-section-divider"></div><h2 data-anchor-id="k72f" id="先看使用效果图">先看使用效果图</h2><div class="md-section-divider"></div><h4 data-anchor-id="rmb2" id="1-人脸相关api-组">1. 人脸相关Api 组</h4><p></p><center data-anchor-id="t4l8"> <img src="https://images-1256032145.cos.ap-beijing.myqcloud.com/api_sdk/VEditor_20181223102525.gif" alt="image"> </center><p></p><p data-anchor-id="xvvb"><br></p><div class="md-section-divider"></div><h4 data-anchor-id="6ysk" id="2-人体相关api-组">2. 人体相关Api 组</h4><p></p><center data-anchor-id="y5fl"><img src="https://images-1256032145.cos.ap-beijing.myqcloud.com/api_sdk/VEditor_20181223113419.gif" alt="image"></center><p></p><p data-anchor-id="eirb"><br></p><div class="md-section-divider"></div><h4 data-anchor-id="cq5t" id="3-文字识别相关api-组">3. 文字识别相关Api 组</h4><p></p><center data-anchor-id="5dtl"><img src="https://images-1256032145.cos.ap-beijing.myqcloud.com/api_sdk/VEditor_20181223113524.gif" alt="image"></center><p></p><p data-anchor-id="kxxr"><br></p><div class="md-section-divider"></div><h4 data-anchor-id="j0oz" id="4-其它api-组">4. 其它Api 组</h4><p></p><center data-anchor-id="fjcj"><img src="https://images-1256032145.cos.ap-beijing.myqcloud.com/api_sdk/VEditor_20181223113611.gif" alt="image"></center><p></p><p data-anchor-id="as5b"><br></p><div class="md-section-divider"></div><h2 data-anchor-id="ok93" id="demo-和-jar-包下载地址">demo  和 jar 包下载地址</h2><p data-anchor-id="qnk4"><a href="https://images-1256032145.cos.ap-beijing.myqcloud.com/api_sdk/lib-facepp_api.jar" target="_blank"> jar 包 下载</a> &nbsp;&nbsp;<a href="https://images-1256032145.cos.ap-beijing.myqcloud.com/api_sdk/lib-facepp_api.jar" target="_blank">https://images-1256032145.cos.ap-beijing.myqcloud.com/api_sdk/lib-facepp_api.jar</a> <br>
<a href="https://github.com/dashewan11111/facepp_api" target="_blank"> jar 包 源码</a> &nbsp;&nbsp;<a href="https://github.com/dashewan11111/facepp_api" target="_blank">https://github.com/dashewan11111/facepp_api</a></p><p data-anchor-id="prkh"><br></p><div class="md-section-divider"></div><h2 data-anchor-id="dwk7" id="使用示例">使用示例</h2><p data-anchor-id="mif2">第一步：组织参数</p><blockquote data-anchor-id="bwdw" class="white-blockquote">
  <p><strong>字符串类的参数全部放到map中</strong></p>
</blockquote><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="m59o"><ol class="linenums"><li class="L0"><code class="language-java"><span class="pln"> </span><span class="typ">Map</span><span class="pun">&lt;</span><span class="typ">String</span><span class="pun">,</span><span class="pln"> </span><span class="typ">String</span><span class="pun">&gt;</span><span class="pln"> params </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">HashMap</span><span class="pun">&lt;&gt;();</span></code></li><li class="L1"><code class="language-java"><span class="pln"> params</span><span class="pun">.</span><span class="pln">put</span><span class="pun">(</span><span class="str">"return_attributes"</span><span class="pun">,</span><span class="pln"> </span><span class="str">"gender,age,smiling,emotion,ethnicity,beauty"</span><span class="pun">);</span></code></li><li class="L2"><code class="language-java"><span class="pln"> params</span><span class="pun">.</span><span class="pln">put</span><span class="pun">(</span><span class="str">"return_landmark"</span><span class="pun">,</span><span class="pln"> </span><span class="str">"2"</span><span class="pun">);</span></code></li></ol></pre><blockquote data-anchor-id="kp7p" class="white-blockquote">
  <p><strong>图片File参数需要转成byte[]</strong> <br>
  PS: 如果不用image_file 参数，而是用image——base64 和 image_url 则不需要这个。所有的方法都提供了有File 参数和无File 参数的重载。</p>
</blockquote><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="9d4c"><ol class="linenums"><li class="L0"><code><span class="kwd">public</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="kwd">byte</span><span class="pun">[]</span><span class="pln"> toByteArray</span><span class="pun">(</span><span class="typ">Bitmap</span><span class="pln"> bitmap</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L1"><code><span class="pln">    </span><span class="typ">ByteArrayOutputStream</span><span class="pln"> baos </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">ByteArrayOutputStream</span><span class="pun">();</span></code></li><li class="L2"><code><span class="pln">    bitmap</span><span class="pun">.</span><span class="pln">compress</span><span class="pun">(</span><span class="typ">Bitmap</span><span class="pun">.</span><span class="typ">CompressFormat</span><span class="pun">.</span><span class="pln">JPEG</span><span class="pun">,</span><span class="pln"> </span><span class="lit">80</span><span class="pun">,</span><span class="pln"> baos</span><span class="pun">);</span></code></li><li class="L3"><code><span class="pln">    </span><span class="kwd">return</span><span class="pln"> baos</span><span class="pun">.</span><span class="pln">toByteArray</span><span class="pun">();</span></code></li><li class="L4"><code><span class="pun">}</span></code></li></ol></pre><p data-anchor-id="h42c"><br>
第二步：调用工具类</p><blockquote data-anchor-id="3byr" class="white-blockquote">
  <p><strong>引用jar包成功之后就可以直接new 对象了。创建FaceppApi实例，直接.出方法。 <br>
  几乎每个方法都有重载，有的带File参数，有的不带。根据自己需要使用。</strong></p>
</blockquote><div class="md-section-divider"></div><pre class="prettyprint linenums prettyprinted" data-anchor-id="pcp0"><ol class="linenums"><li class="L0"><code class="language-java"><span class="typ">FaceppApi</span><span class="pln"> faceppApi </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">FacePPApi</span><span class="pun">(自己的</span><span class="pln">key</span><span class="pun">,</span><span class="pln"> </span><span class="pun">自己的</span><span class="pln">secret</span><span class="pun">);</span></code></li><li class="L1"><code class="language-java"></code></li><li class="L2"><code class="language-java"><span class="pln">faceppApi</span><span class="pun">.</span><span class="pln">detectHumanBody</span><span class="pun">((</span><span class="pln">params</span><span class="pun">,</span><span class="pln"> </span><span class="typ">BitmapUtil</span><span class="pun">.</span><span class="pln">toByteArray</span><span class="pun">(</span><span class="pln">bitmap</span><span class="pun">),</span><span class="pln"> </span></code></li><li class="L3"><code class="language-java"><span class="pln">    </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">IFacePPCallBack</span><span class="pun">&lt;</span><span class="typ">HumanBodyDetectResponse</span><span class="pun">&gt;()</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L4"><code class="language-java"><span class="pln">            </span><span class="lit">@Override</span></code></li><li class="L5"><code class="language-java"><span class="pln">            </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> onSuccess</span><span class="pun">(</span><span class="typ">HumanBodyDetectResponse</span><span class="pln"> humanBodyDetectResponse</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L6"><code class="language-java"><span class="pln">               </span><span class="com">// 自己的业务处理</span></code></li><li class="L7"><code class="language-java"><span class="pln">            </span><span class="pun">}</span></code></li><li class="L8"><code class="language-java"></code></li><li class="L9"><code class="language-java"><span class="pln">            </span><span class="lit">@Override</span></code></li><li class="L0"><code class="language-java"><span class="pln">            </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> onFailed</span><span class="pun">(</span><span class="typ">String</span><span class="pln"> s</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L1"><code class="language-java"><span class="pln">               </span><span class="com">// 自己的失败处理</span></code></li><li class="L2"><code class="language-java"><span class="pln">            </span><span class="pun">}</span></code></li><li class="L3"><code class="language-java"><span class="pln">        </span><span class="pun">});</span></code></li></ol></pre><p data-anchor-id="94rv"><br></p><div class="md-section-divider"></div><h2 data-anchor-id="rz0l" id="android-studio-工程引用工具类步骤">android studio 工程引用工具类步骤</h2><div class="md-section-divider"></div><h4 data-anchor-id="vvyr" id="1-jar包放到libs-下">1. jar包放到libs 下</h4><blockquote data-anchor-id="7dvx" class="white-blockquote">
  <p><img src="https://images-1256032145.cos.ap-beijing.myqcloud.com/api_sdk/11.png" alt="image"></p>
</blockquote><p data-anchor-id="dpbe"><br></p><div class="md-section-divider"></div><h4 data-anchor-id="rgn7" id="2-添加依赖">2. 添加依赖</h4><blockquote data-anchor-id="gfkg" class="white-blockquote">
  <p><img src="https://images-1256032145.cos.ap-beijing.myqcloud.com/api_sdk/22.png" alt="image"></p>
</blockquote><hr></div>
</body>
</html>